const Base = require('./base.js');

module.exports = class extends Base {
    indexAction() {
        return this.display();
    }

    async listAction() {
        return this.display();
    }

    async updateAction() {
        let model = this.model('user');
        if (this.isPost) {
            let data = this.post();
            try {
                let success = await model.where({id: data.id}).update(data);
                let userinfo = await this.assign('userinfo');
                let user = await model.where({id: userinfo.id}).find();
                await this.session('userinfo', user);
                return this.json(success);
            } catch (e) {
                return this.json('2');
            }
        } else {
            return this.fail('500', '请求格式错误！');
        }
    }

};


